package com.mashang.mapper;

import com.mashang.domain.Clazz;
import com.mashang.util.JdbcUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class ClazzMapper {

    public Clazz selectById(Long id) {

        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        Clazz clazz = null;

        try {
            connection = JdbcUtil.getConnection();
            statement = connection.createStatement();
            String sql = "select * from b_clazz where class_id = " + id;
            rs = statement.executeQuery(sql);
            clazz = new Clazz();
            while (rs.next()) {
                clazz.setName(rs.getString("name"));
                clazz.setClassId(rs.getLong("class_id"));
                clazz.setClassNo(rs.getString("class_no"));
                clazz.setRemark(rs.getString("remark"));
                clazz.setType(rs.getString("type"));
                clazz.setCreateTime(rs.getString("create_time"));
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtil.close(connection, statement, rs);
            return clazz;
        }


    }
}
